home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / utils / dtr.arc / dtr.c next >
Encoding:
C/C++ Source or Header  |  1987-01-18  |  2.5 KB  |  100 lines

  1. /*
  2.  
  3.    DTR control program. Called from Shell or Desktop. Rename to DTR.PRG
  4.  
  5.        if placed in AUTO folder.
  6.  
  7.    Call:
  8.  
  9.        DTR {"on"|"off"}
  10.  
  11.    Assumes "off" if no argument.
  12.  
  13.  
  14.  
  15. Written by Bruce D. Nelson 1/18/87 Megamax C.
  16.  
  17. */
  18.  
  19.  
  20.  
  21. #include <osbind.h>
  22.  
  23. #include <string.h>
  24.  
  25.  
  26.  
  27. extern giaccess();
  28.  
  29. extern rdbt();
  30.  
  31. extern dtron();
  32.  
  33. extern dtroff();
  34.  
  35. extern setbt();
  36.  
  37. extern clrbt();
  38.  
  39.  
  40.  
  41.  
  42.  
  43. asm{
  44.  
  45.  
  46.  
  47. giaccess:
  48.  
  49.     move.w    SR,-(A7)    /* save status */
  50.  
  51.     ori.w    #0x700,SR    /* IPL 7, disable ints */
  52.  
  53.     movem.l D1-D2/A0,-(A7)    /* Save regs */
  54.  
  55.     lea    0xFFFF8800,A0    /* Adr of Sound Chip */
  56.  
  57.     move.b    D1,D2        /* Get reg # */
  58.  
  59.     and.b    #15,D1        /* reg 0-15 */
  60.  
  61.     move.b    D1,(A0)        /* select reg */
  62.  
  63.     asl.b    #1,D2        /* test read/write bit */
  64.  
  65.     bcc    rdbt(PC)    /* go read */
  66.  
  67.     move.b    D0,2(A0)    /* write data to sound chip register */
  68.  
  69. rdbt:    moveq   #0,D0
  70.  
  71.     move.b    (A0),D0        /* read byte from sound chip register */
  72.  
  73.     movem.l (A7)+,D1-D2/A0  /* restore registers */
  74.  
  75.     move.w    (A7)+,SR    /* restore status */
  76.  
  77.     rts
  78.  
  79.  
  80.  
  81. dtroff:
  82.  
  83.     moveq    #16,D2        /* set dtr bit */
  84.  
  85.     bra    setbt(PC)    /* go set bit */
  86.  
  87.  
  88.  
  89. dtron:
  90.  
  91.     moveq     #-17,D2        /* clear dtr bit */
  92.  
  93.     bra    clrbt(PC)    /* go clear bit */
  94.  
  95.  
  96.  
  97. setbt:
  98.  
  99.     movem.l    D0-D2,-(A7)    /* Save registers */
  100.  
  101.     move.w    SR,-(A7)    /* Save status */
  102.  
  103.     ori.w    #0x700,SR    /* IPL 7, disable ints */
  104.  
  105.     moveq    #14,D1        /* port A */
  106.  
  107.     move.l    D2,-(A7)    /* save bit # */
  108.  
  109.     bsr    giaccess(PC)    /* Select port A */
  110.  
  111.     move.l    (A7)+,D2    /* bit # back */
  112.  
  113.     or.b    D2,D0        /* Set bits */
  114.  
  115.     moveq    #0x8E,D1    /* Write to port A */
  116.  
  117.     bsr    giaccess(PC)    /* write new value */
  118.  
  119.     move.w    (A7)+,SR    /* Restore status */
  120.  
  121.     movem.l    (A7)+,D0-D2    /* restore regs */
  122.  
  123.     rts
  124.  
  125.  
  126.  
  127. clrbt:
  128.  
  129.     movem.l    D0-D2,-(A7)    /* Save registers */
  130.  
  131.     move.w    SR,-(A7)    /* Save status */
  132.  
  133.     ori.w    #0x700,SR    /* IPL 7, disable ints */
  134.  
  135.     moveq    #14,D1        /* port A */
  136.  
  137.     move.l    D2,-(A7)    /* save bit # */
  138.  
  139.     bsr    giaccess(PC)    /* Select port A */
  140.  
  141.     move.l    (A7)+,D2    /* bit # back */
  142.  
  143.     and.b    D2,D0        /* Set bits */
  144.  
  145.     moveq    #0x8E,D1        /* Write to port A */
  146.  
  147.     bsr    giaccess(PC)    /* write new value */
  148.  
  149.     move.w    (A7)+,SR    /* Restore status */
  150.  
  151.     movem.l    (A7)+,D0-D2    /* restore regs */
  152.  
  153.     rts
  154.  
  155. }
  156.  
  157.     
  158.  
  159. /* main - Determine if argument is "on" or "off". Assume "off" if no arg.
  160.  
  161.           Process DTR accordingly. */
  162.  
  163.  
  164.  
  165.     
  166.  
  167. main(argc,argv)
  168.  
  169. int argc;
  170.  
  171. char *argv[];
  172.  
  173. {
  174.  
  175.     if(argc > 1 && strcmp(argv[1],"on")==0){
  176.  
  177.         Supexec(&dtron);
  178.  
  179.         printf ("DTR has been turned on\n");
  180.  
  181.     }
  182.  
  183.     else{
  184.  
  185.         Supexec(&dtroff);
  186.  
  187.         printf ("DTR has been turned off\n");
  188.  
  189.     }
  190.  
  191.     
  192.  
  193. }
  194.  
  195.  
  196.  
  197.  
  198.  
  199.